﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QLNS.aspFrm
{
    public partial class frmDanhSachCanBoCongChucLanhDao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var dscanbo = context.GetDanhSachCanBoCongChucLanhDao();
            System.Data.DataTable table = MakeTable();
            foreach (var i in dscanbo)
            {
                System.Data.DataRow row;
                row = table.NewRow();
                row["HoTen"] = i.HoTen;
                if (i.GioiTinh == "Nam")
                {
                    row["GioiTinhNam"] =  String.Format("{0:d/M/yyyy}",i.NgaySinh);
                }
                else if (i.GioiTinh == "Nữ")
                {
                    row["GioiTinhNu"] = String.Format("{0:d/M/yyyy}", i.NgaySinh);
                }
                if (i.ChucVuKiemNhiem == "")
                {
                    row["ChucVuChinh"] = i.ChucVuChinh;
                }
                else
                {
                    row["ChucVuChinh"] = i.ChucVuChinh + " kiêm " + i.ChucVuKiemNhiem;
                }
                row["MaNgachCC"] = i.MaNgachCC;
                row["TenNgachCC"] = i.TenNgachCC;
                row["ChuyenMon"] = i.ChuyenMon;
                row["TrinhDoQLNN"] = i.QLNN;
                row["TrinhDoTinHoc"] = i.TinHoc;
                row["TrinhDoNgoaiNgu"] = i.NgoaiNgu;
                row["TrinhDoLLCT"] = i.LyLuanChinhTri;
                row["NgayThamGiaCongTac"] = String.Format("{0:d/M/yyyy}", i.NgayThamGiaCongTac);

                    row["NgayKetNapDang"] = String.Format("{0:d/M/yyyy}", i.NgayKetNapDang);

                row["NgayVaoChinhThuc"] = String.Format("{0:d/M/yyyy}",i.NgayVaoChinhThuc);
                row["TenNhom"] = i.tenNhom;
                row["IdNhomChucVu"] = i.IdNhomChucVu;
                row["IdDonVi"]=i.IDDonVi;
                row["DonVi"] = i.DonVi;
                row["NgayGiuChucVu"] = String.Format("{0:d/M/yyyy}",i.NgayGiuChucVu);
                table.Rows.Add(row);
            }
            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//Report_DanhSachCanBoCongChucLanhDao.rpt";
            //Loading Report
            rd.Load(strRptPath);

            // Setting report data source
            if (table != null)
                rd.SetDataSource(table);
            CrystalReportViewer1.ReportSource = rd;
        }

        private System.Data.DataTable MakeTable()
        {
            System.Data.DataTable table = new System.Data.DataTable("Table");
            System.Data.DataColumn column;

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "HoTen";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "GioiTinhNam";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "GioiTinhNu";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ChucVuChinh";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "MaNgachCC";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TenNgachCC";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ChuyenMon";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TrinhDoQLNN";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TrinhDoNgoaiNgu";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TrinhDoTinHoc";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TrinhDoLLCT";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayThamGiaCongTac";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayKetNapDang";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayVaoChinhThuc";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TenNhom";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.ColumnName = "IdNhomChucVu";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.ColumnName = "IdDonVi";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "DonVi";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayGiuChucVu";
            table.Columns.Add(column);

            return table;
        }
    }
}